package org.bubuntux.jatural.core;

//TODO: use a custom point??
import java.awt.Point;
import java.util.HashMap;
import java.util.Map;

public class Board {

	private Element[][] grid;
	private Map<Number, Point[]> playerPieces;

	protected Board(Element[][] grid, Map<Number, Point[]> playerPieces) {
		super();
		this.grid = grid;
		this.playerPieces = playerPieces;
	}

	public Board(int width, int height) {
		this(new Element[width][height], new HashMap<Number, Point[]>());
	}

	public void addPieces(Number playerId, Element[] pieces) {
		if (pieces.length > grid.length) {
			throw new IllegalArgumentException(
					"The count of pieces, can't be greater than the width of the board");
		}
		Point[] playerPoints = getInitialPosition(pieces.length);
		int piece = 0;
		for (Point point : playerPoints) {
			grid[point.x][point.y] = pieces[piece++];
		}
		playerPieces.put(playerId, playerPoints);
	}

	private Point[] getInitialPosition(int amount) {
		Point[] initialPoints = new Point[amount];
		int x = grid.length / 2;
		for (int i = 0; i < initialPoints.length; i++) {
			initialPoints[i] = new Point(x++, grid[0].length);
		}
		return initialPoints;
	}

	public void movePieces(Number playerId, Direction direction) {

	}

	public void rotatePieces(Number playerId, Direction direction) {

	}

}
